package gui;

import javax.jms.Session;
import javax.jms.Topic;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import actions.LoginAction;
import actions.SendMessageAction;

@SuppressWarnings("serial")
public class InputPanel extends JPanel {
	private JTextField textField;
	private JButton btnSend;
	private SendMessageAction sma;
	private JButton btnLogin;
	//private JButton btnRegister;
	/**
	 * Create the panel.
	 */
	public InputPanel(Session session, Topic topic) {
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		
		textField = new JTextField();
		sma = new SendMessageAction(textField,session, topic);
		//sma=new SendMessageAction(textField);
		textField.addActionListener(sma);
		add(textField);
		textField.setColumns(10);
		
		btnSend = new JButton("Send");
		btnSend.addActionListener(sma);
		add(btnSend);
		
		JSeparator separator = new JSeparator();
		separator.setOrientation(SwingConstants.VERTICAL);
		this.add(separator);
		
		btnLogin = new JButton("Login");
		btnLogin.addActionListener(new LoginAction());
		this.add(btnLogin);
		this.disableSending();
		/*
		btnRegister = new JButton("Register");
		this.add(btnRegister);*/
	}
	
	public void enableSending() {
		sma.setEnabled(true);
		textField.setEditable(true);
		btnSend.setEnabled(true);
	}

	public void disableSending() {
		sma.setEnabled(false);
		textField.setEditable(false);
		btnSend.setEnabled(false);
	}
	
	public void enableLogin(boolean login) {
		btnLogin.setEnabled(login);
	}
}
